function minimumTotal(triangle: number[][]): number {
  const bottom = triangle[triangle.length - 1];
  const ans = new Array(bottom.length);
  for (let i = 0; i < ans.length; i++) {
    ans[i] = bottom[i];
  }
  for (let i = ans.length - 2; i >= 0; i--) {
    for (let j = 0; j < triangle[i].length; j++) {
      ans[j] = Math.min(ans[j], ans [j + 1]) + triangle[i][j];
    }
  }
  return ans[0];
};